<?php
$week_array = BUtils::WeekDayKeys(7, true);

//business icon url
$icon_url = Yii::app()->baseUrl . '/img/icons/icon_others.png';
if (!empty($row['category_key'])) {
	$icon_url = Yii::app()->baseUrl . '/img/icons/icon_'.$row['category_key'].'.png';
}

if (empty($row['seo_id'])) {
	$bizLink = Yii::app()->createUrl('/place/view', array('id'=>$row['id_merchant']));
} else {
	$bizLink = Yii::app()->createUrl('/place/view', array('id'=>$row['seo_id']));
}
?>
<!-- content -->
<div class="section-wrapper post-w">
<div class="container">
<div class="row">
	<div class="span5 offset1">
		<div class="white-card no-padding relative">
			<div style="padding:12px; font-size:20px; line-height:32px;">
				<img src="<?php echo $icon_url; ?>" style="width:24px;" alt="" />
				<a href="<?php echo $bizLink; ?>"><?php echo $row['name']; ?></a>
			</div>
			<?php BHelper::HtmlOfferView($row); ?>
		</div>
	</div>
	<div class="span5">
		<div class="white-card relative">
			<div style="text-align:center;">
				<h4 class="blue"><?php echo BUtils::T('get_free_app_lbl') ?></h4>
			</div>
			<div style="text-align:center;">
				<a href="<?php echo Yii::app()->createUrl('app/mobile', array('download'=>1, 'type'=>'iphone', 'ref'=>$row['id'])); ?>" target="_blank"><img src="<?php echo Yii::app()->baseUrl; ?>/img/app-store-icon.png" alg="Yamii in App Store" style="width:100px;" /></a>
				<a href="<?php echo Yii::app()->createUrl('app/mobile', array('download'=>1, 'type'=>'android', 'ref'=>$row['id'])); ?>" target="_blank"><img src="<?php echo Yii::app()->baseUrl; ?>/img/google-play-icon.png" alg="Yamii in Google Play Store" style="width:100px;" /></a>
			</div>
		</div>
		<div class="white-card no-padding relative">
			<div class="title-bar" style="padding:4px 8px;">
				<h4 class="red"><?php echo BUtils::T('specials_nearby'); ?></h4>
			</div>
			<div style="height:500px; overflow:auto;">
<?php
$now_ts = time();
foreach ($special_rows as $r) {
	//set offer picture
	$url_thumb_default = Yii::app()->baseUrl . '/img/default_special_thumb.png';
	$url_picture_default = Yii::app()->baseUrl . '/img/default_special_picture.png';
	$url_thumb = empty($r['url_picture']) ? $r['url_offer_img'] : $r['url_picture'];
	if (!empty($url_thumb)) {
		$url_thumb = BUtils::GetOfferPictureUrl($url_thumb);
		$url_picture = str_replace('thumb_', '', $url_thumb);
	} else {
		$url_thumb = $url_thumb_default;
		$url_picture = $url_picture_default;
	}
	
	//set the valid_time
	$range_time = BUtils::GetHourRangeFormat($r['start_hour'], $r['end_hour'], $r['show_hours']);
	
	//set the day string
	$week_string = BUtils::GetWeekdays($r['week_days'], $week_array);
	$range_date = BUtils::GetRecentDayName($r['week_days'], $week_string, ($this->action->id == 'next24'), $r['start_hour']);
	if ($r['uts_start_date'] > $now_ts or $now_ts > $r['uts_end_date']) {
		$range_date = $week_string;
	}
	
	//business area
	$biz_area = '';
	if (!empty($r['biz_area'])) {
		$biz_area = '<div class="area label">'.$r['biz_area'].'</div>';
	}
	
	//set distance
	$distance = '';
	if (!empty($r['distance'])) {
		$distance = (float)sprintf('%.2f', $r['distance']);
		if ($distance < 1.0) {
			$distance = sprintf('%d m', $distance * 100);
		} else {
			$distance = $distance . ' km';
		}
		$distance = '<i class="icon-location-arrow"></i> <span> '.$distance.'</span>';
	}
	
	//set price, discount or highlight
	$highlight = $del_price = '';
	if (!empty($r['price'])) {
		$highlight = MerchantObject::formatPrice($r['price']);
		if (!empty($r['value'])) {
			$del_price = '<span class="oldprice label">€'.$r['value'].'</span>';
		}
	} elseif (!empty($r['discount'])) {
		$highlight = MerchantObject::formatDiscount($r['discount']);
	}
	
	//business icon url
	$biz_icon = Yii::app()->baseUrl . '/img/icons/icon_others.png';
	if (!empty($r['category_key'])) {
		$biz_icon = Yii::app()->baseUrl . '/img/icons/icon_'.$r['category_key'].'.png';
	}
	
	//offer content
	$content = strip_tags(trim($r['content']));
	
	//offer view link
	$offer_link = Yii::app()->createUrl('/special/view', array('id' => $r['id']));
	echo <<<HTML
<div class="mb_offer">
	<div class="mb_merchant">
		<div class="distance">
			{$distance}
		</div>
		<div class="name">
			<img src="{$biz_icon}" style="width:16px;" alt="" />
			<span>{$r['name']}</span>
		</div>
		<div class="clearfix"></div>
	</div>
	<div class="mb_picture">
		<a href="{$offer_link}"><img src="{$url_thumb}" alt="" onError="this.onerror=null;this.src='{$url_thumb_default}';" /></a>
	</div>
	<div class="mb_price">
		<div class="highlight">{$highlight}</div>
		{$del_price}
	</div>
	<div class="mb_period">
		<div class="time">{$range_time}</div>
		<div class="date">{$range_date}</div>
	</div>
	<div class="clearfix"></div>
	<div>
		<div class="mb_text">{$content}</div>
	</div>
</div>
HTML;
}
?>
			</div>
		</div>
	</div>
</div>
</div>
</div>